package com.study.opcua.config;

import com.study.opcua.utils.OpcClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OpcUaRunner implements ApplicationRunner {

    @Autowired
    private OpcParams opcParams;

    @Override
    public void run(ApplicationArguments args) {
        // 建立opc连接
        List<OpcParams.Interfaces> interfaces = opcParams.getInterfaces();
        if(interfaces != null && interfaces.size() > 0){
            for(OpcParams.Interfaces i : interfaces){
                if(i.getUrl() != null && !"".equals(i.getUrl())){
                    OpcClientUtil.connectClient(i.getUrl());
                }
            }
        }
    }
}
